/*****************************************************************************/
exports.controllers={
	admin_rewrites: function(space) {
		if (!space.roles.pages) return "Access denied";
		var mode=space.fields.mode||"list";
		switch (mode) {
			case "list":
				space.rewrites=space.site.sql.execute_and_fetch("rewrites/list");
				space.pages=space.site.sql.execute_and_fetch_h("pages/list_admin_fkey");
				space.pages.unshift({id:"",name:""});
				return space.views.process("widgets/admin_rewrites/list",space);
			case "save":
				var hashes=space.functions.parse_grids(space).rewrites;
				space.functions.save_grid(space,hashes,"rewrites",{
					existing: function(hash,id) {return {}},
					insert: function(hash,id) {},
					update: function(hash,id) {hash.rewrite_id=id;},
					delold: function(hash,id) {hash.rewrite_id=id;}
				});
				return JSON.stringify({redirect:{url:space.action+"?mode=ok"}});
			case "ok":
				return space.views.process("widgets/save_ok",space);
		}
	}
};

/*****************************************************************************/
